﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using JCode.Model;
using JCode.BLL;
namespace JCodeManage.Category
{
   
    public partial class CategoryEdit : Form
    {
        JCode.Model.CategoryInfo model = new JCode.Model.CategoryInfo();
        JCode.BLL.Category bll = new JCode.BLL.Category();
        bool isAdd = true;
        /// <summary>
        /// 添加或者编辑分类
        /// </summary>
        /// <param name="parentId">分类ID</param>
        /// <param name="b">true 添加</param>
        public CategoryEdit(int ParentID,bool b)
        { 
            InitializeComponent();
            model.ParentID = ParentID;
            isAdd = b;
            if (!b)
            {
                model = bll.GetModel(ParentID);
                
                txtname.Text = model.CategoryName;
                btnadd.Text = "修改分类";
                groupBox1.Text = "修改类别";
            }
           
        }

        private void btnadd_Click(object sender, EventArgs e)
        {
            if (isAdd)
            {
                model.CategoryName = txtname.Text;
                
                bll.Add(model);
                MessageBox.Show("添加成功");
                this.Close();
            }
            else
            {
                model.CategoryName = txtname.Text;
                bll.Update(model);
                MessageBox.Show("修改成功");
                this.Close();
            }
        }
    }
}
